package com.cj.controller;


import com.cj.po.PageInfo;
import com.cj.po.Student;
import com.cj.service.ClassService;
import com.cj.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 用户控制器类
 */
@Controller
public class ClassController {
    @Autowired
    private ClassService classService;

    /**
     * 分页查询
     * pageIndex 当前页码
     * pageSize  显示条数
     */
    @RequestMapping(value = "/findClass")
    public String findStudent(Integer c_id, Integer c_classid,String c_classname,String c_counsellor,
                              Integer pageIndex, Integer pageSize, Model model) {

        PageInfo<Class> ci = classService.findPageInfo(c_id,c_classid,c_classname,
                c_counsellor,pageIndex,pageSize);
        model.addAttribute("ci",ci);
        model.addAttribute("c_id",c_id);
        return "class_list";
    }

    /**
     * 导出Excel
     * @return
     */
    @RequestMapping(value = "/exportclasslist", method = RequestMethod.POST)
    @ResponseBody
    public List<Class> exportClass(){
        List<Class> classList = classService.getAll();
        return classList;
    }

    /**
     * 删除学生信息
     */
    @RequestMapping( "/deleteClass")
    @ResponseBody
    public String deleteClass(Integer c_id) {
        int c = classService.deleteClass(c_id);
        return "class_list";
    }


    /**
     * 添加学生信息
     */

    @RequestMapping(value = "/addClass" ,method = RequestMethod.POST)
    @ResponseBody
    public String addClass(@RequestBody Class ucalss) {
        int s = classService.addClass(ucalss);
        return "student_list";
    }

    /**
     * 修改学生信息
     */
    @RequestMapping(value = "/updateClass" ,method = RequestMethod.POST )
    public String updateClass( Class ucalss) {
        int s = classService.updateClass(ucalss);
        return "redirect:/findClass";
    }


    @RequestMapping( "/findClassById")
    public String findClassById(Integer c_id,HttpSession session) {

        Class c= classService.findClassById(c_id);
        session.setAttribute("c",c);
        return "class_edit";
    }
}
